package com.aaa.mks.controller;

import com.aaa.common.util.Result;
import com.aaa.common.constants.ReturnStatus;
import com.aaa.mks.entity.TravelNodes;
import com.aaa.mks.service.TravelNodesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TravelNodes)表控制层
 *
 * @author makejava
 * @since 2021-02-22 10:36:01
 */
@RestController
@RequestMapping("travelNodes")
@ApiOperation("travelNodes控制器")
public class TravelNodesController {
    /**
     * 服务对象
     */
    @Resource
    private TravelNodesService travelNodesService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("单个对象查询")
    public Result selectOne(Integer id) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(),
                this.travelNodesService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody TravelNodes travelNodes) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(),
                this.travelNodesService.queryAll(pageNo, pageSize, travelNodes));
    }

    /**
     * 新增数据
     *
     * @param travelNodes 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result insert(@RequestBody TravelNodes travelNodes) {
        System.out.println(travelNodes);
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(),
                this.travelNodesService.insert(travelNodes));
    }

    /**
     * 修改数据
     *
     * @param travelNodes 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result update(@RequestBody TravelNodes travelNodes) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(),
                this.travelNodesService.update(travelNodes));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer id) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(),
                this.travelNodesService.deleteById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAllByDictData")
    public Result queryAllByDictData() {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(),
                this.travelNodesService.queryAllByDictData());
    }
}